package com.yc.bran.snack.util;

import java.io.File;  
import java.io.FileInputStream;  
import java.io.IOException;  
import java.security.MessageDigest;  
import java.security.NoSuchAlgorithmException;  
import java.math.BigInteger;  
  
public class ImageUtils {  
    public static String calculateMD5(File file) throws NoSuchAlgorithmException, IOException {  
        try (FileInputStream fis = new FileInputStream(file)) {  
            MessageDigest md = MessageDigest.getInstance("MD5");  
            byte[] buffer = new byte[1024];  
            int read;  
            while ((read = fis.read(buffer)) != -1) {  
                md.update(buffer, 0, read);  
            }  
            byte[] digest = md.digest();  
            return new BigInteger(1, digest).toString(16);  
        }  
    }  
}